layui.define(['table', 'form','my_send','laydate'], function(exports){
    var $ = layui.$
    ,table = layui.table
    ,form = layui.form
    , laydate = layui.laydate
    ,http_proxy = layui.http_proxy;
    function getDiff(s1,s2){
        var days = s2.getTime() - s1.getTime();
        var time = parseInt(days / (1000 * 60 * 60 * 24));
        return time;
    }
    laydate.render({
        elem: '#productionDate'
    });
    laydate.render({
        elem: '#guaranteeDate'
    });
    laydate.render({
        elem: '#installDate'
    });
    laydate.render({
        elem: '#firstRepairDate'
    });
    laydate.render({
        elem: '#repairDate'
        ,done: function(value, date, endDate){
            var nextRepairDates = new Date($('#nextRepairDate').val());
            var repairDate =  new Date(value);
            var DiffTime = getDiff(repairDate,nextRepairDates);
            $('#interval').val(DiffTime+'天');
            $('#maintainNext').val(DiffTime+'天')
        }
    });
    laydate.render({
        elem: '#nextRepairDate'
        ,done: function(value, date, endDate){
            var nextRepairDate = new Date(value);
            var repairDate =  new Date($('#repairDate').val());
            var DiffTime = getDiff(repairDate,nextRepairDate);
            $('#interval').val(DiffTime+'天');
            $('#maintainNext').val(DiffTime+'天')
        }
    });
    // 专业名称
    $.ajax({
        url:http_proxy('/devStatus/getDomain'),
        async: false,
        dataType:'json',
        type:'get',
        success:function(data){
            $.each(data.result,function(index,item){
                var laValue = item.label+"#@***#!-"+item.value;
                $('#majorList').append(new Option(item.label,laValue));
            })
            form.render('select');
        }
    });
    // 系统名称
    form.on('select(majorListFilter)', function(data){
        var laValueArray = data.value.split("#@***#!-");
        $.ajax({
            url:http_proxy('/devStatus/getSystem?parentId=')+laValueArray[1],
            async: false,
            dataType:'json',
            type:'get',
            success:function(data){
                $("#systemList").empty();
                if(data.result != ""){
                    $("#systemList").append(new Option("请选择",""));
                    $.each(data.result,function(index,item){
                        var laValue = item.label+"#@***#!-"+item.value;
                        $('#systemList').append(new Option(item.label,laValue));
                    })
                }else{
                    $("#systemList").append(new Option("无数据",""));
                }
                form.render('select');
            }
        });
    })
    // 设备名称
    form.on('select(systemListFilter)', function(data){
        var laValueArray = data.value.split("#@***#!-");
        $.ajax({
            url:http_proxy('/devStatus/getDevice?parentId=')+laValueArray[1],
            async: false,
            dataType:'json',
            type:'get',
            success:function(data){
                $("#equipmentList").empty();
                if(data.result != ""){
                    $("#equipmentList").append(new Option("请选择",""));
                    $.each(data.result,function(index,item){
                        $('#equipmentList').append(new Option(item.label,item.label));
                    })
                }else{
                    $("#equipmentList").append(new Option("无数据",""));
                }
                form.render('select');
            }
        });
    })
    // 线路编号
    $.ajax({
        url:http_proxy('/devStatus/getLine'),
        async: false,
        dataType:'json',
        type:'get',
        success:function(data){
            $.each(data.rows,function(index,item){
                $('#lineId').append(new Option(item.label,item.value));
            })
            form.render('select');
        }
    });
    //所属站点
    form.on('select(lineIdFilter)', function(data){
        $.ajax({
            url:http_proxy('/devStatus/getEtStation?line_id=')+data.value,
            async: false,
            dataType:'json',
            type:'get',
            success:function(data){
                $("#etStation").empty();
                if(data.rows != ""){
                    $("#etStation").append(new Option("请选择",""));
                    $.each(data.rows,function(index,item){
                        $('#etStation').append(new Option(item.value,item.value));
                    })
                }else{
                    $("#etStation").append(new Option("无数据",""));
                }
                form.render('select');
            }
        });
    })
    form.on('select(is_plan)', function(data){
        if (data.value==1){
            $('.itemShow').show();
        }else {
            $('.itemShow').hide();
        }
    })

    exports('currency', {})
});